home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / mui / MCC_Tron0_7.lha / MCC_Tron / Source / brush2c.c next >
C/C++ Source or Header  |  1996-10-25  |  4KB  |  136 lines

  1. /*
  2. ** This little program can be used to convert an ILBM brush
  3. ** to something that MUI's Bodychunk class can understand.
  4. **
  5. ** Perfect for about logos and stuff like that...
  6. **
  7. ** Have fun, 
  8. ** Stefan.
  9. */
  10.  
  11. /* SMAKE */
  12.  
  13. #include "exec/types.h"
  14. #include "exec/memory.h"
  15. #include "libraries/dos.h"
  16. #include "libraries/iffparse.h"
  17. #include "datatypes/pictureclass.h"
  18. #include "graphics/gfx.h"
  19. #include "proto/dos.h"
  20. #include "proto/iffparse.h"
  21. #include "stdlib.h"
  22. #include "string.h"
  23. #include "stdio.h"
  24. #include "ctype.h"
  25.  
  26.  
  27. #define to32(c) (((c)<<24)|((c)<<16)|((c)<<8)|(c))
  28.  
  29.  
  30. int main(int argc,char **argv)
  31. {
  32.     char name[100],uname[100],*c;
  33.     struct IFFHandle *iff;
  34.     struct ContextNode *cn;
  35.     struct StoredProperty *sp;
  36.     struct BitMapHeader *bmhd;
  37.     UBYTE *body;
  38.     int size,i;
  39.     UBYTE *cols;
  40.  
  41.     if (argc<2 || argc>3 || argv[1][0]=='?')
  42.     {
  43.         printf("Syntax: %s ilbm-file\n",argv[0]);
  44.         exit(20);
  45.     }
  46.  
  47.     stccpy(name,argv[1],100);
  48.     if (c=strchr(name,'.')) *c=0;
  49.     strcpy(uname,name);
  50.     for (c=uname;*c;c++)
  51.         *c=toupper(*c);
  52.  
  53.     if (iff=AllocIFF())
  54.     {
  55.         if (iff->iff_Stream=Open(argv[1],MODE_OLDFILE))
  56.         {
  57.             InitIFFasDOS(iff);
  58.  
  59.             if (!OpenIFF(iff,IFFF_READ))
  60.             {
  61.                 if (!ParseIFF(iff,IFFPARSE_STEP))
  62.                 {
  63.                     if ((cn=CurrentChunk(iff)) && (cn->cn_ID==ID_FORM))
  64.                     {
  65.                         if (cn->cn_Type==ID_ILBM)
  66.                         {
  67.                             if (!PropChunk(iff,ID_ILBM,ID_BMHD) &&
  68.                                 !PropChunk(iff,ID_ILBM,ID_CMAP) &&
  69.                                 !StopChunk(iff,ID_ILBM,ID_BODY) &&
  70.                                 !StopOnExit(iff,ID_ILBM,ID_FORM) &&
  71.                                 !ParseIFF(iff,IFFPARSE_SCAN))
  72.                             {
  73.                                 if (sp=FindProp(iff,ID_ILBM,ID_CMAP))
  74.                                 {
  75.                                     cols = (UBYTE *)sp->sp_Data;
  76.  
  77.                                     printf("#ifdef USE_%s_COLORS\n",uname);
  78.                                     printf("const ULONG %s_colors[%ld] =\n{\n",name,sp->sp_Size);
  79.                                     for (i=0;i<sp->sp_Size;i+=3)
  80.                                         printf("\t0x%08lx,0x%08lx,0x%08lx,\n",to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]));
  81.                                     printf("};\n");
  82.                                     printf("#endif\n\n");
  83.                                 }
  84.  
  85.                                 if (sp=FindProp(iff,ID_ILBM,ID_BMHD))
  86.                                 {
  87.                                     bmhd = (struct BitMapHeader *)sp->sp_Data;
  88.  
  89.                                     if ((bmhd->bmh_Compression==cmpNone) || (bmhd->bmh_Compression==cmpByteRun1))
  90.                                     {
  91.                                         size = CurrentChunk(iff)->cn_Size;
  92.  
  93.                                         if (body=malloc(size))
  94.                                         {
  95.                                             if (ReadChunkBytes(iff,body,size)==size)
  96.                                             {
  97.                                                 fprintf(stderr,"Width %d Height %d Depth %d - converting...\n",bmhd->bmh_Width,bmhd->bmh_Height,bmhd->bmh_Depth);
  98.  
  99.                                                 printf("#define %s_WIDTH       %3d\n",uname,bmhd->bmh_Width);
  100.                                                 printf("#define %s_HEIGHT      %3d\n",uname,bmhd->bmh_Height);
  101.                                                 printf("#define %s_DEPTH       %3d\n",uname,bmhd->bmh_Depth);
  102.                                                 printf("#define %s_COMPRESSION %3d\n",uname,bmhd->bmh_Compression);
  103.                                                 printf("#define %s_MASKING     %3d\n",uname,bmhd->bmh_Masking);
  104.                                                 printf("\n");
  105.  
  106.                                                 printf("#ifdef USE_%s_HEADER\n",uname);
  107.                                                 printf("const struct BitMapHeader %s_header =\n{ %ld,%ld,%ld,%ld,%ld,%ld,%ld,0,%ld,%ld,%ld,%ld,%ld };\n",name,bmhd->bmh_Width,bmhd->bmh_Height,bmhd->bmh_Left,bmhd->bmh_Top,bmhd->bmh_Depth,bmhd->bmh_Masking,bmhd->bmh_Compression,bmhd->bmh_Transparent,bmhd->bmh_XAspect,bmhd->bmh_YAspect,bmhd->bmh_PageWidth,bmhd->bmh_PageHeight);
  108.                                                 printf("#endif\n\n");
  109.  
  110.                                                 printf("#ifdef USE_%s_BODY\n",uname);
  111.                                                 printf("const UBYTE %s_body[%ld] = {\n",name,size);
  112.                                                 for (i=0;i<size;i++)
  113.                                                 {
  114.                                                     printf("0x%02lx,",body[i]);
  115.                                                     if (!((i+1)%15)) printf("\n");
  116.                                                 }
  117.                                                 printf(" };\n");
  118.                                                 printf("#endif\n");
  119.                                             }
  120.                                             free(body);
  121.                                         }
  122.                                     }
  123.                                 }
  124.                             }
  125.                         }
  126.                     }
  127.                 }
  128.                 CloseIFF(iff);
  129.             }
  130.             Close(iff->iff_Stream);
  131.         }
  132.         FreeIFF(iff);
  133.     }
  134.     return(0);
  135. }
  136.